#!/bin/sh
GIT_HOME=/developer/git-repository/
DEST_PATH=/product/front/

if [ ! -n "$1" ];
then
  echo -e "Please input a project name! You can input as follows:"
  echo -e "./fe-deploy.sh Try_Webpack_React"
  exit
fi

if [ $1 = "Try_Webpack_React" ];
then
  echo -e "----------------Enter Project----------------"
  cd $GIT_HOME$1
else
  echo -e "Invalid Project Name!"
  exit
fi

# clear dist
echo -e "----------------Clean Dist----------------"
rm -fr ./dist

echo -e "----------------Git Pull----------------"
git pull
#git branch -D pro
#git checkout -b pro origin/master

echo -e "----------------Yarn Install----------------"
yarn

echo -e "----------------Yarn Run Build----------------"
yarn run build

if [ -d "./dist" ];
then
  echo -e "----------------Clean Product Dist----------------"
  rm -rf $DEST_PATH/$1/dist

  echo -e "----------------Copy Dist----------------"
  cp -R ./dist $DEST_PATH/$1/

  echo -e "----------------Deploy Success----------------"
else
  echo -e "----------------Deploy Failed----------------"
fi

echo -e "----------------Copy fe-deploy.sh----------------"
#cp -R $GIT_HOME$1/fe-deploy.sh /developer/

echo -e "----------------Copy nginx config----------------"
#sudo cp -R $GIT_HOME$1/nginx /usr/local/nginx/vhost